﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;

namespace MonkeyWarranty.Web.WarrantyTickets
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static WarrantyTicketBiz _warrantyTicketBiz;
        private static WarrantyTicketBiz WarrantyTicketManager
        {
            get { return _warrantyTicketBiz ?? (_warrantyTicketBiz = new WarrantyTicketBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod(EnableSession = true)]
        public static object TicketListByFilter(int status, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            var ticketCount = WarrantyTicketManager.GetTicketCount(jtStartIndex, jtPageSize, jtSorting, status);
            var warrantyTicketViews = WarrantyTicketManager.GetTickets(jtStartIndex, jtPageSize, jtSorting, status);

            foreach (var warrantyTicketView in warrantyTicketViews)
            {
                warrantyTicketView.CreatedTimeString = string.Format("{0:HH:mm}", warrantyTicketView.CreatedDate);
                switch (warrantyTicketView.ReceivedFrom)
                {
                    case 1:
                        warrantyTicketView.ReceivedFromName = Resources.GlobalStrings.Customers;
                        break;
                    case 2:
                        warrantyTicketView.ReceivedFromName = Resources.GlobalStrings.Employees;
                        warrantyTicketView.DealerEmployeeName = warrantyTicketView.FromEmployeeName;
                        break;
                    case 3:
                        warrantyTicketView.ReceivedFromName = Resources.GlobalStrings.Dealers;
                        warrantyTicketView.DealerEmployeeName = warrantyTicketView.FromDealerName;
                        break;
                }
            }

            return new { Result = "OK", Records = warrantyTicketViews, TotalRecordCount = ticketCount };
            //return WarrantyTicketManager.GetTicketsWs(jtStartIndex, jtPageSize, jtSorting, 0);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteTicket(long Id)
        {
            WarrantyTicketManager.DeleteTicket(Id);
            return new { Result = "OK" };
        }
    }
}